//
//  TKYTitleView.m
//  StationHouseHelper
//
//  Created by apple on 2018/6/19.
//  Copyright © 2018年 铁科院. All rights reserved.
//

#import "TKYTitleView.h"
#import "TKYTitleViewCell.h"
#define KTKYTitleViewCellID @"TKYTitleViewCell"
@interface TKYTitleView()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic, strong)UICollectionView *collectionView;

@property (nonatomic, strong)NSArray *imageArr;
@property (nonatomic, strong)NSArray *titleArr;

@end
@implementation TKYTitleView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self addSubview: self.collectionView];
        self.imageArr = @[@"safety_problem",@"quality_problem",@"progress_report"];
        self.titleArr = @[@"安全",@"质量", @"进度"];
    }
    return self;
}

#pragma mark--懒加载
/**
 初始化
 */
- (UICollectionView *)collectionView{
    if (!_collectionView) {
        UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
        layout.itemSize = CGSizeMake((kScreenWidth-3)/3,kHeightScale *75);
        //layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        layout.minimumLineSpacing = 1;
        layout.minimumInteritemSpacing = 1;
        //layout.sectionInset = UIEdgeInsetsMake(0, 20, 0, 20);
        UICollectionView *collectionView;
        collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, self.kx_height) collectionViewLayout:layout];
        collectionView.delegate = self;
        collectionView.dataSource = self;
        collectionView.backgroundColor = [UIColor whiteColor];
        collectionView.bounces = YES;
        
        collectionView.showsVerticalScrollIndicator = YES;
        collectionView.showsHorizontalScrollIndicator = YES;
        _collectionView = collectionView;
      //  [self.collectionView registerNib:[UINib nibWithNibName:@"TKYTitleViewCell" bundle:nil] forCellWithReuseIdentifier:KTKYTitleViewCellID];
        [self.collectionView registerClass:[TKYTitleViewCell class] forCellWithReuseIdentifier:KTKYTitleViewCellID];

    }
    return _collectionView;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 3;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    TKYTitleViewCell *cell= [collectionView dequeueReusableCellWithReuseIdentifier:KTKYTitleViewCellID forIndexPath:indexPath];
    //cell.backgroundColor = [UIColor redColor];
    cell.imageV.image = [UIImage imageNamed:self.imageArr[indexPath.row]];
    cell.titleLabel.text = self.titleArr[indexPath.row];
    return cell;
}

#pragma mark - UICollectionViewDelegateFlowLayout
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if ([self.delegate respondsToSelector:@selector(tky_titleViewDidSelectItemAtIndexPath:)]) {
        [self.delegate tky_titleViewDidSelectItemAtIndexPath:indexPath];
    }
}


                
@end
